
// 上传路线图册
if ($('.detail_imgul img').length == 0) {
	$('.detail_imgul').hide()
	$('.detail_sss').removeClass('detail_s')
}else{
	$('.detail_imgul').show()
	$('.detail_sss').addClass('detail_s')
}

// 上传图片img
uploadimg()
function uploadimg(){
	var lengths = $('.detail_imgul li').length
	var vals = []
	for (var i = 0; i < lengths; i++) {
		var srcval = $('.detail_imgul li').eq(i).find('img').attr('src')
		vals.push(srcval)
		$('.detail_add_imginput').val('')
		$('.detail_add_imginput').val(vals)
	}
}
function ajaxFileUpload() {
	var f = document.getElementById("fileupload").files;
	
			if (f[0].size<= 2097152) {
				$.ajaxFileUpload({
					
					url: URL + 'business/attachment/ajax_upload_image',
					secureuri: false,
					fileElementId: 'fileupload',
					dataType:'json',
					success: function(data, status) {
						if (data.code == 200010) {
							upload();
							$('.detail_imgul').show()
							$('.detail_imgul').append('<li><img src="'+data.content.image_url+'" ><div class="detail_imguldel"><img src="'+URLs+'/images/del.png" alt="" /></div></li>')
							$('.detail_sss').addClass('detail_s');
							uploadimg()
						}else{
							alert(data.message)
						}

						
					},
					error: function(data, status, e) {
						console.log('error')
					}
				})
			}else{
				alert('文件太大')
			}

	return false;
}

$('.detail_add_img').on('click','.detail_imguldel',function(event) {
	$(this).parents('li').remove()
	uploadimg()
});
// 初始化图册上传控件
var upload = function() {
	$('#fileupload').change(function(event) {
		ajaxFileUpload();
	});
}
upload();







// 默认的省市

if ($('.Country_input').attr('data-country') == '0') {
	var pid = '693000'
}else{

	var pid = $('.Country_input').attr('data-country')
}


if ($('.Country_input').attr('data-city') == '0') {
	// var pid = '693000'
}else{

	var cid = $('.City_input').attr('data-city')
}




$.ajax({
	url: URL+'area/ajax_list_children',
	type: 'GET',
	dataType: 'json',
	data: {
		parent_id: 0
	},
	success: function(data) {
		var data = data.content;
		for (var i = 0; i < data.data.length; i++) {
			$('.Country_input').append('<option data-id="' + data.data[i].short_name + '"  value ="'+data.data[i].id+'">'+data.data[i].short_name+'</option>');
		}

		console.log(pid)
		$(".Country_input").find("option[value=" + pid +"]").attr('selected', 'selected');
		// var defaultpid = $('.Country_input').find("option:selected").attr('data-id')
		
		citys(pid)
		
	}
	
})

$('.Country_input').change(function(event) {
	var pid = $(this).find("option:selected").val()
	citys(pid)
});
var citys = function(pid) {

	$.ajax({
		url: URL+'area/ajax_list_children/' + pid,
		type: 'GET',
		dataType: 'json',
		success: function(data) {

			var data = data.content;
			$('.City_input').html('')
			for (var i = 0; i < data.data.length; i++) {
				$('.City_input').append('<option data-id="' + data.data[i].short_name + '"  value ="'+data.data[i].id+'">'+data.data[i].short_name+'</option>');
			}

			$(".City_input").find("option[value=" + cid +"]").attr('selected', 'selected');
		}
	})
}




// 修改添加保存
$('#submit_btn').click(function() {


	$.ajax({
		url: URL+'business/merchant/ajax_update',
		type: 'POST',
		data: $('#form').serialize(),
		success:function(data){
			var datas= JSON.parse(data)

			alert(datas.message)

		}
	})

	
	
	
});


